package com.itqf.ipmsys.controller;


import com.itqf.ipmsys.utils.R;
import com.itqf.ipmsys.dto.PoliceFindDto;
import com.itqf.ipmsys.entity.Police;
import com.itqf.ipmsys.service.PoliceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 警员表 前端控制器
 * </p>
 *
 * @author corn
 * @since 2021-09-22
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/police")
public class PoliceController {

    @Autowired
    private PoliceService policeService;

    @Autowired
    private AdminController adminController;

    /**
     * 警员信息展示
     *      1. 展示所有警员信息
     *      2. 按条件展示警员信息
     * @param policeFindDto
     * @return
     */
    @PostMapping(value = "list", consumes = "application/json;charset=utf-8")
    public Object findPoliceList(@RequestBody PoliceFindDto policeFindDto){
        return policeService.findAllPoliceList(policeFindDto);
    }

    /**
     * 增加警员信息
     *
     * @param
     * @return
     */
    @PostMapping(value = "add", consumes = "application/json;charset=utf-8")
    public Object addPolice(@RequestBody Police police){
        return policeService.addPolice(police);
    }

    /**
     * 删除警员信息
     *
     * @param
     * @return
     */
    @PostMapping(value = "del", consumes = "application/json;charset=utf-8")
    public Object delPolice(@RequestBody Police police){
        return policeService.delPolice(police);
    }

    /**
     * 更新警员信息
     *
     * @param
     * @return
     */
    @PostMapping(value = "update", consumes = "application/json;charset=utf-8")
    public Object updatePolice(@RequestBody Police police){
        return policeService.updatePolice(police);
    }

    /**
     * 警员密码重置
     *
     * @param
     * @return
     */
    @PostMapping(value = "resetpw", consumes = "application/json;charset=utf-8")
    public Object resetPassword(@RequestBody Police police){
        //1. 根据用户id,调用用户服务,重置密码
        int rows = adminController.resetPassword(police);
        //2. 判断返回值,是否成功
        if (rows > 0) {
            return R.ok("更新成功").setCode(200);
        }
        return R.error("更新失败").setCode(501);
    }

}

